<template>
	<view class="template-product tn-safe-area-inset-bottom">
		<!-- 顶部自定义导航 -->
		<!-- 顶部自定义导航开始 -->
		<view class="tn-navbg" :style="{height: vuex_custom_bar_height + 'px'}">
			<!-- 顶部自定义导航 -->
			<tn-nav-bar fixed alpha customBack :bottomShadow="false" backgroundColor="#FFFFFF">
				<view slot="back" class='tn-custom-nav-bar__back' @click="goBack">
					<text class='icon tn-icon-left'></text>
					<text class='icon tn-icon-home-capsule-fill'></text>
				</view>
				<view class="tn-flex tn-flex-col-center tn-flex-row-evenly">
					<text class="tn-text-bold tn-text-xl tn-color-black">答题结果分析</text>
				</view>
			</tn-nav-bar>
		</view>
		<!-- 顶部自定义导航结束 -->

		<!-- 用户基础信息开始 -->
		<view class="tn-padding-top-sm tn-padding-bottom-sm">
			<view class="user-info" style="display: flex;">
				<view class="user-info-left">
					<view class="user-avatar">
						<tn-avatar :src="userInfo.avatar" size="lg" imgMode="scaleToFill"></tn-avatar>
					</view>
					<view class="user-nickname">
						<text>{{userInfo.nickname}}</text>
					</view>
				</view>
				<view class="user-info-right">
					<tn-list-view>
						<tn-list-cell :unlined="true" padding="10rpx 30rpx" fontSize="26">
							<view style="display: flex;justify-content: space-between;">
								<view>等级荣耀：砖石三</view>
								<view class="tn-icon-share-square" style="font-size: 30rpx;"></view>
							</view>
						</tn-list-cell>
						<tn-list-cell :unlined="true" padding="10rpx 30rpx" fontSize="26">答题积分：120.09</tn-list-cell>
						<tn-list-cell :unlined="true" padding="10rpx 30rpx" fontSize="26">注册时间：2023.12.12</tn-list-cell>
					</tn-list-view>
				</view>
			</view>
		</view>
		<!-- 用户基础信息结束 -->

		<!-- 边距间隔 -->
		<view class="tn-strip-bottom"></view>

		<!-- 试卷信息开始 -->
		<view class="tn-padding-top-sm tn-padding-bottom-sm">
			<view class="tn-flex">
				<view class="tn-margin-sm tn-padding-top-xs" style="width: 100%;">
					<view class="tn-text-lg tn-text-bold clamp-text-1 tn-text-justify">
						<text class="" style="line-height: 60rpx;font-size: 24rpx;">{{submitInfo.title}}</text>
					</view>
					<view class="tn-flex tn-flex-col-between tn-margin-top-xs">
						<view class="justify-content-item tn-tag-content__item tn-margin-right tn-text-sm">
							<text class="tn-icon-time tn-padding-right-xs tn-text-lg"></text>
							<text class="tn-text-df">{{submitInfo.time}}</text>
						</view>
						<view class="justify-content-item tn-tag-content__item tn-margin-right tn-text-sm">
							<text class="tn-icon-equal tn-padding-right-xs tn-text-lg"></text>
							<text class="tn-padding-right tn-text-df">{{submitInfo.exam_score.toFixed(2)}}</text>
							<text class="tn-icon-all tn-padding-right-xs tn-text-lg"></text>
							<text class="tn-text-df" v-if="submitInfo.level === 1">简单</text>
							<text class="tn-text-df" v-if="submitInfo.level === 2">较难</text>
							<text class="tn-text-df" v-if="submitInfo.level === 3">中等</text>
							<text class="tn-text-df" v-if="submitInfo.level === 4">困难</text>
						</view>
					</view>
				</view>
				<view class="image-pic tn-margin-sm" :style="'background-image:url('+ submitInfo.image +')'">
					<view class="image-article"></view>
				</view>
			</view>
		</view>
		<!-- 试卷信息结束 -->

		<view class="tn-strip-bottom"></view>

		<!-- 答题汇总开始 -->
		<view class="tn-padding-top-sm tn-padding-bottom-sm">
			<view class="tn-flex tn-flex-col-center">
				<view class="tn-margin-left-sm tn-text-bold">答题结果</view>
				<view @click="showTip('本次答题结果')" class="icon1__item--icon tn-flex tn-flex-row-center tn-flex-col-center"
					style="color: #7C8191;margin-left: 10rpx;">
					<view class="tn-icon-tip-fill"></view>
				</view>
			</view>
			<view class="tn-flex tn-flex-row-center tn-radius tn-padding-top">
				<view class="tn-padding-sm tn-margin-xs tn-radius">
					<view class="tn-flex tn-flex-direction-column tn-flex-row-center tn-flex-col-center">
						<view class="icon12__item--icon tn-flex tn-flex-row-center tn-flex-col-center">
							<view class="tn-color-wallpaper tn-text-bold">总分</view>
						</view>
						<view class="tn-text-center">
							<text class="tn-text-ellipsis">{{submitInfo.exam_score.toFixed(2)}}</text>
						</view>
					</view>
				</view>
				<view class="tn-padding-sm tn-margin-xs tn-radius">
					<view class="tn-flex tn-flex-direction-column tn-flex-row-center tn-flex-col-center">
						<view class="icon12__item--icon tn-flex tn-flex-row-center tn-flex-col-center">
							<view class="tn-color-wallpaper tn-text-bold">正确</view>
						</view>
						<view class="tn-text-center">
							<text class="tn-text-ellipsis tn-color-green">{{submitInfo.correct_count}}</text>
						</view>
					</view>
				</view>
				<view class="tn-padding-sm tn-margin-xs tn-radius">
					<view class="tn-flex tn-flex-direction-column tn-flex-row-center tn-flex-col-center">
						<view class="icon12__item--icon tn-flex tn-flex-row-center tn-flex-col-center">
							<view class="tn-color-wallpaper tn-text-bold">错误</view>
						</view>
						<view class="tn-text-center tn-color-red">
							<text class="tn-text-ellipsis">{{submitInfo.error_count}}</text>
						</view>
					</view>
				</view>
				<view class="tn-padding-sm tn-margin-xs tn-radius">
					<view class="tn-flex tn-flex-direction-column tn-flex-row-center tn-flex-col-center">
						<view class="icon12__item--icon tn-flex tn-flex-row-center tn-flex-col-center">
							<view class="tn-color-wallpaper tn-text-bold">得分</view>
						</view>
						<view class="tn-text-center">
							<text class="tn-text-ellipsis">{{submitInfo.score.toFixed(2)}}</text>
						</view>
					</view>
				</view>
				<view class="tn-padding-sm tn-margin-xs tn-radius">
					<view class="tn-flex tn-flex-direction-column tn-flex-row-center tn-flex-col-center">
						<view class="icon12__item--icon tn-flex tn-flex-row-center tn-flex-col-center">
							<view class="tn-color-wallpaper tn-text-bold">时长</view>
						</view>
						<view class="tn-text-center">
							<text class="tn-text-ellipsis">{{submitInfo.submit_exam_time || '暂无统计'}}</text>
						</view>
					</view>
				</view>

			</view>
		</view>
		<!-- 答题汇总结束 -->

		<view class="tn-strip-bottom"></view>

		<!-- 信息流广告开始 -->
		<block v-if="showAd">
			<view class="">
				<view class="tn-tag-content tn-margin tn-text-justify">
					<ad unit-id="adunit-65c56a85e788fe7b"></ad>
				</view>
			</view>
			<!-- 信息流广告结束 -->

			<!-- 边距间隔 -->
			<view class="tn-strip-bottom"></view>
		</block>

		<!-- 试卷排行开始-->
		<view class="tn-padding-top-sm tn-padding-bottom-sm" style="padding-bottom: 200rpx;">
			<view class="tn-flex tn-flex-col-center">
				<view class="tn-margin-left-sm tn-text-bold">答题排名</view>
				<view @click="showTip('答题历史排名')" class="icon1__item--icon tn-flex tn-flex-row-center tn-flex-col-center"
					style="color: #7C8191;margin-left: 10rpx;">
					<view class="tn-icon-team-fill"></view>
				</view>
			</view>
			<block v-for="(item, index) in rankList">
				<view class="" :key="index">
					<tn-list-cell :hover="true" :unlined="true" :radius="true" :fontSize="24">
						<view class="tn-flex tn-flex-col-center">
							<view class="icon1__item--icon tn-flex tn-flex-row-center tn-flex-col-center">
								<view class="" style="display: flex;align-items: center;">
									<text style="padding-right: 20rpx;">第{{ index + 1 }}名</text>
									<img :src="item.avatar" alt="" srcset="" style="width: 50rpx;height: 50rpx;border-radius: 50%;">
								</view>
							</view>
							<view class="tn-margin-left-sm tn-flex-1" style="padding-right: 20rpx;">{{item.nickname}}</view>
							<view>{{item.score.toFixed(2) + ` 积分`}}</view>
						</view>
					</tn-list-cell>
				</view>
			</block>
		</view>
		<!-- 试卷排行结束 -->

		<!-- 底部导航开始 -->
		<view id="top-info" class="tn-footerfixed tn-safe-area-inset-bottom tn-bg-white"
			:style="{transform: `translateY(${topInfoTranslateY}px)`}">
			<view class="tn-flex tn-flex-row-between tn-flex-col-center">
				<view class="tn-flex-2 justify-content-item">
					<view class="tn-flex tn-flex-row-center">
						<view class="tn-flex-1">
							<view class="tn-icon-share" style="font-size: 42rpx;"></view>
							<view class="tn-text-center tn-text-sm tn-padding-top-xs">分享</view>
						</view>
						<view class="tn-flex-1 tn-padding-right-xl" @click="subscribe">
							<button class="tn-button--clear-style" style="border-radius: 0;">
								<view class="tn-icon-notice" style="font-size: 42rpx;"></view>
								<view class="tn-text-center tn-text-sm tn-padding-top-xs">订阅</view>
							</button>
						</view>
					</view>
				</view>
				<view class="tn-flex-3 justify-content-item tn-padding-top-sm tn-padding-bottom-sm">
					<tn-button shape="round" @click="previewQRCodeImage" backgroundColor="#27B93A" padding="38rpx 0" width="40%"
						:fontSize="30" shadow>
						<text class="tn-color-white" hover-class="tn-hover" :hover-stay-time="150">
							在线指导
						</text>
					</tn-button>
					<tn-button shape="round" @click="onlineExam(collectionContent.uid, 2)" backgroundColor="tn-main-gradient-blue"
						padding="38rpx 0" margin="0 0 0 30rpx" width="40%" :fontSize="30" shadow>
						<text class="tn-color-white" hover-class="tn-hover" :hover-stay-time="150">
							答题分析
						</text>
					</tn-button>
				</view>
			</view>
		</view>
		<!-- 底部导航结束 -->
	</view>
</template>

<script>
	import template_page_mixin from '@/libs/mixin/template_page_mixin.js'
	import {
		getSubmitInfo,
		getRankListByCollection
	} from "@/utils/api/exam.js"
	import {
		getUserBasicInfo
	} from "@/utils/api/user.js"
	export default {
		name: 'TemplateProduct',
		mixins: [template_page_mixin],
		data() {
			return {
				topInfo: {
					height: 0,
				},
				showAd: getApp().globalData.showAd,
				topInfoTranslateY: 0,
				prevScrollTop: 0,
				collectionUid: "",
				submit_uid: "",
				groupList: [], // 头像原生数据
				groupAvatarList: [], //头像组装数据
				collectionContent: {},
				submitInfo: {},
				rankList: [],
				rankSearchWhere: {
					page: 1,
					size: 20,
					uid: ''
				},
				loadState: true,
				userInfo: {},
			}
		},
		onReady() {
			this.getTopInfoRect()
		},
		onPageScroll(e) {
			this.handlePageScroll(e.scrollTop)
		},
		onLoad(params) {
			this.submit_uid = params.uid || ""
			this.$t.mpShare = {
				share: false
			}
			if (!this.$t.mpShare.share) {
				uni.hideShareMenu()
			}
		},
		onShow() {
			this.getSubmitCollectionInfo()
			this.getUserInfo()
		},
		methods: {
			// 获取用户信息
			getUserInfo() {
				getUserBasicInfo().then(res => {
					this.userInfo = res.data
				})
			},
			// 显示弹窗信息
			showTip(e) {
				this.$func.showToast(e)
			},
			// 获取答题排行
			getSubmitRankList() {
				if (!this.loadState) {
					return
				}
				getRankListByCollection(this.rankSearchWhere).then(res => {
					if (res.code == 100) {
						this.rankList.push(...res.data.items)
						this.rankSearchWhere.page = res.data.page + 1
						this.rankSearchWhere.size = res.data.size
						if (res.data.items.length === 0) {
							this.loadState = false
							this.$func.showToast("排名已到底啦")
						}
						return
					}
					this.$func.showTotast(res.msg)
				})
			},
			// 获取答卷详情
			getSubmitCollectionInfo() {
				getSubmitInfo({
					uid: this.submit_uid
				}).then(res => {
					if (res.code == 100) {
						this.submitInfo = res.data.info
						this.rankSearchWhere.uid = res.data.info.collection_uid
						this.getSubmitRankList()
						return
					}
					this.$func.showTotast(res.msg)
				})
			},
			onlineExam(uid, type) {
				this.$func.showToast('努力开发中')
				return
				if (res.code == 100) {
					if (type == 1) {
						this.tn("/subpages/help/list")
					} else {
						this.$func.showToast("待开发中")
						//this.tn("/subpages/exam/reading/list?uid=" + uid)
					}
				} else {
					this.$func.showToast("请先登录")
					this.tn("/subpages/user/login")
				}

			},
			// 预览作者图片
			previewQRCodeImage() {
				this.$func.previewQRCodeImage()
			},
			// 跳转
			tn(e) {
				this.$func.navigatorTo(e)
			},
			// 微信订阅消息
			async subscribe() {
				let subscribeResult = await this.$func.templateSubscribe(getApp().globalData.rewardNotifyTemplateId)
				let code = subscribeResult.code || 0
				if (code == 100) {
					this.$func.showToast("订阅成功")
					return
				}
				this.$func.showToast("订阅失败")
			},
			// 获取顶部销售信息容器相关信息
			getTopInfoRect() {
				this._tGetRect('#top-info').then((res) => {
					if (!res) {
						setTimeout(() => {
							this.getTopInfoRect()
						}, 50)
						return
					}
					this.topInfo.height = res.height
				})
			},
			// 处理页面滚动事件
			handlePageScroll(scrollTop) {
				if (this.prevScrollTop > scrollTop) {
					// 内容下滑，即手指从下往上滚
					this.topInfoTranslateY = 0
				} else {
					// 内容上滑，即手指从上往下滚
					if (scrollTop > this.topInfo.height) {
						this.topInfoTranslateY = this.topInfo.height
					}
				}
				this.prevScrollTop = scrollTop
			},
		},
		onReachBottom() {
			this.getSubmitRankList()
		}
	}
</script>

<style lang="scss" scoped>
	.home-shadow {
		border-radius: 15rpx;
		box-shadow: 0rpx 0rpx 50rpx 0rpx rgba(0, 0, 0, 0.07);
	}

	// 答题汇总开始
	.user-info-left {
		width: 35%;
		display: flex;
		flex-direction: column;
		align-content: center;
		text-align: center;
	}

	.user-nickname {
		margin-top: 10rpx;
		font-size: 26rpx;
	}

	.user-info-right {
		width: 65%;
		text-align: left;
	}

	/* 图标容器12 start */
	.icon12 {
		&__item {
			width: 30%;
			background-color: #FFFFFF;
			border-radius: 10rpx;
			padding: 30rpx;
			margin: 20rpx 10rpx;
			transform: scale(1);
			transition: transform 0.3s linear;
			transform-origin: center center;

			&--icon {
				width: auto;
				height: 15rpx;
				font-size: 30rpx;
				margin-bottom: 38rpx;
				position: relative;
				z-index: 1;

				&::after {
					content: " ";
					position: absolute;
					z-index: -1;
					width: 100%;
					height: 100%;
					left: 0;
					bottom: 0;
					border-radius: inherit;
					opacity: 1;
					transform: scale(1, 1);
					background-size: 100% 100%;

				}
			}
		}
	}

	// 答题汇总结束


	// 试卷基础信息开始
	.clamp-text-1 {
		-webkit-line-clamp: 3;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		text-overflow: ellipsis;
		overflow: hidden;
	}

	.user-avatar {
		-webkit-line-clamp: 1;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		text-overflow: ellipsis;
		overflow: hidden;
	}

	/* 试题列表图片 start*/
	.image-article {
		border-radius: 8rpx;
		width: 220rpx;
		height: 120rpx;
		position: relative;
	}

	.image-design {
		padding: 140rpx 0rpx;
		font-size: 40rpx;
		font-weight: 300;
		position: relative;
	}

	.image-pic {
		background-size: cover;
		background-repeat: no-repeat;
		// background-attachment:fixed;
		background-position: top;
		border-radius: 10rpx;
	}

	// 试卷基础信息结束

	.tn-flex-row-center {
		justify-content: space-between;
	}

	.template-product {}

	.tn-tabbar-height {
		min-height: 20rpx;
		height: calc(40rpx + env(safe-area-inset-bottom) / 2);
	}

	/* 胶囊*/
	.tn-custom-nav-bar__back {
		width: 100%;
		height: 100%;
		position: relative;
		display: flex;
		justify-content: space-evenly;
		align-items: center;
		box-sizing: border-box;
		background-color: rgba(0, 0, 0, 0.15);
		border-radius: 1000rpx;
		border: 1rpx solid rgba(255, 255, 255, 0.5);
		color: #FFFFFF;
		font-size: 18px;

		.icon {
			display: block;
			flex: 1;
			margin: auto;
			text-align: center;
		}

		&:before {
			content: " ";
			width: 1rpx;
			height: 110%;
			position: absolute;
			top: 22.5%;
			left: 0;
			right: 0;
			margin: auto;
			transform: scale(0.5);
			transform-origin: 0 0;
			pointer-events: none;
			box-sizing: border-box;
			opacity: 0.7;
			background-color: #FFFFFF;
		}
	}

	/* 间隔线 start*/
	.tn-strip-bottom-min {
		width: 100%;
		border-bottom: 1rpx solid #F8F9FB;
	}

	/* 间隔线 start*/
	.tn-strip-bottom {
		width: 100%;
		border-bottom: 20rpx solid rgba(241, 241, 241, 0.8);
	}

	/* 间隔线 end*/
	/* 标题 start */
	.nav_title {
		-webkit-background-clip: text;
		color: transparent;

		&--wrap {
			position: relative;
			display: flex;
			height: 120rpx;
			font-size: 46rpx;
			align-items: center;
			justify-content: center;
			font-weight: bold;
			background-image: url(https://tnuiimage.tnkjapp.com/title_bg/title44.png);
			background-size: cover;
		}
	}

	/* 标题 end */


	/* 底部*/
	.tn-footerfixed {
		position: fixed;
		background-color: rgba(255, 255, 255, 0.5);
		box-shadow: 0rpx 0rpx 30rpx 0rpx rgba(0, 0, 0, 0.07);
		bottom: 0;
		width: 100%;
		transition: all 0.25s ease-out;
		will-change: transform;
		z-index: 100;
	}

	/* 底部 start*/
	.footerfixed {
		position: fixed;
		width: 100%;
		bottom: 0;
		z-index: 999;
		box-shadow: 0rpx 0rpx 30rpx 0rpx rgba(0, 0, 0, 0.07);
	}
</style>